<template>
<div class="layout">
	<Row type="flex">
		<Col :span="24">
			<Breadcrumb>
				<BreadcrumbItem to="/" @click.native="changeMenu"><Icon type="home"></Icon> 首页</BreadcrumbItem>
				<BreadcrumbItem>{{title}}</BreadcrumbItem>
			</Breadcrumb>
			<div class="cleaner10"></div>
		</Col>

		<Col :span="6">
			<Card>
				<p slot="title">支付渠道选择</p>
				<CellGroup>
					<Cell v-for="(item,index) in vPayment" :title="item.name" :key="'payment'+index"><i-switch @on-change="onSubmit('payment',index)" v-model="vPayment[index]['value']" :true-value="1" :false-value="0" slot="extra"/></Cell>
				</CellGroup>
			</Card>
			<div class="cleaner10"></div>
			<Card>
				<p slot="title">图片分组</p>
				<a href="javascript:void(0)" slot="extra" @click.prevent="">新增</a>
				<CellGroup>
					<Cell v-for="(item,index) in vImages" :title="item.name" :key="'images'+index"><i-switch @on-change="onSubmit('images',index)" v-model="vImages[index]['value']" :true-value="1" :false-value="0" slot="extra"/></Cell>

				</CellGroup>
			</Card>
			<div class="cleaner10"></div>
			
		</Col>

		<Col :span="18">
			<Card style="margin-left:10px">
				<p slot="title">情感标签</p>
				<a href="javascript:void(0)" slot="extra" @click.prevent="">新增</a>
				<Row type="flex">
					<Col v-for="(item,index) in vEmotion" :key="'emotion'+index" :span="8">
						<CellGroup>
							<Cell :title="item.name" :key="'emotion'+index"><i-switch @on-change="onSubmit('emotion',index)" v-model="vEmotion[index]['value']" :true-value="1" :false-value="0" slot="extra"/></Cell>
						</CellGroup>
					</Col>
				</Row>
			</Card>
			<div class="cleaner10"></div>
		</Col>
	</Row>
	<!-- <Modal v-model="showDetail" title="详情" cancel-text="">
		<div v-html="currentContent"></div>
    </Modal> -->
</div>
</template>
<script>


// 引入子组件
import {mapState,mapGetters} from 'vuex'
import {  CellGroup,Cell,Card, FormItem,Form, Modal, Divider,Row, Col, Button, Breadcrumb, BreadcrumbItem, Icon, Input } from 'iview';
import { isNullOrUndefined } from 'util';
export default { 
	name:'setting-basic-index',
	components: { CellGroup,Cell,Card, FormItem,Form,  Modal, Divider,Row, Col, Button, Breadcrumb, BreadcrumbItem, Icon, Input},
	data () {
		return {
			title:'基本设置',
			vForm:{
				34:0,
				35:1,
			},
			vPayment:[],
			vImages:[],
			vEmotion:[],
		}
	},
	methods:{
		init:function(){
			let self=this
			self.$Spin.show()
			self.$http.get("/v1/linkages",{params: { 'token': self.token }})
			.then(function(response){
				if(200==response.data.status && 0==response.data.code && response.data.data.length>0)
				{
					response.data.data.forEach(item=>{
						if(12==item.type_id){
							self.vPayment.push({id:item.id,name:item.name,value:parseInt(item.status)})
						}else if(13==item.type_id){
							self.vImages.push({id:item.id,name:item.name,value:parseInt(item.status)})
						}else if(14==item.type_id){
							self.vEmotion.push({id:item.id,name:item.name,value:parseInt(item.status)})
						}
					})
				}
				self.$Spin.hide()
			}).catch(function(error){
				self.$Spin.hide()
				self.$Message.error(error.message)
			})
		},
		onSubmit:function(vType,index){
			let self=this
			let _form = {}
			if('payment'==vType){_form={id:self.vPayment[index]['id'],status:self.vPayment[index]['value']}}
			else if('emotion'==vType){_form={id:self.vEmotion[index]['id'],status:self.vEmotion[index]['value']}}
			else if('images'==vType){_form={id:self.vImages[index]['id'],status:self.vImages[index]['value']}}
			self.$Spin.show()
			self.$http.post("/v1/linkages?_method=put&token="+self.token,{data:JSON.stringify(_form)})
			.then(function(response){
				if(200==response.data.status && 0==response.data.code)
				{
					self.$Message.info('保存成功');
				}
				self.$Spin.hide()
			}).catch(function(error){
				self.$Spin.hide()
				self.$Message.error(error.message)
			})
		}
	},
	created:function(){
	},
	mounted () {
		this.init()
    	this.setTitle(this.title)
	},
	activated:function(){
		// this.init()
	},
	computed:{
		...mapGetters(['token']),
	},
	watch:{
		realname(curVal,oldVal){
			if(''==curVal){this.uidKey=null}
		}
	}
}



</script>
<style lang="less" scoped>
</style>